<?php
/**
 * Created by PhpStorm.
 * Author: WZS
 * User: 17732
 * Date: 2018/9/9
 * Time: 13:27
 */

namespace app\index\validate;


use app\lib\exception\CommentException;
use think\Request;
use think\Validate;

class BaseValidate extends Validate
{
    public function goCheck(){
        // 获取http传入的参数
        // 对这些参数做校验
        $request = Request::instance();
        $params = $request->param();
        $result = $this->batch()->check($params);
        if(!$result){
            $ex = new CommentException([
                'msg' => $this->error,
            ]);
            throw $ex;
        }
        else{
            return true;
        }
    }
    // 对输入进行验证 防止sql注入
    protected function isSqlFuck($value){
        $rule = '/select|insert|and|or|update|delete|union|into|load_file|outfile|from|count\(|drop table|update|truncate|asc\(|mid\(|char\(|xp_cmdshell|exec|master|\/\*|\*|\.\.\/|\.\//i';
        $result = preg_match($rule,$value);
        if(!$result){
            return true;
        }
        else{
            return false;
        }
    }

    // 验证分页加载   页码是否为正整数
    protected function isPositiveInteger($value,$rule = '',$data = '',$field = ''){
        if(is_numeric($value) && is_int($value+0) && ($value+0) > 0){
            return true;
        }
        else{
            return false;
        }
    }


}